#[macro_use]
extern crate validator_derive;
// extern crate validator;

pub mod api;
pub mod md_content;
pub mod model;
pub mod search;
pub mod utils;

use sqlx::SqlitePool;
use std::sync::Arc;
use tempfile::TempDir;

#[derive(Clone)]
pub struct GlobalState {
    db: SqlitePool,
    tempdir: Arc<TempDir>,
}

impl GlobalState {
    pub fn new(db: SqlitePool) -> anyhow::Result<GlobalState> {
        Ok(GlobalState {
            db: db,
            tempdir: Arc::new(tempfile::tempdir()?),
        })
    }
}

pub type Request = tide::Request<GlobalState>;
